﻿using GetWebsite;
using DSFramework;
using Quartz.Impl;
using Quartz;
using GetWebsite.Blogs.Blogs;

string dbConfig = ConfigHelper.ReadText();
SQL.InitSQL("", $"{dbConfig}", "", "", "SQLite");

//程序启动时从数据库加载数据到缓存
CnBlog.caches = SQL.DB.Queryable<CnBlogInfo>().Where(b => b.IsSendToEmail == 0).ToList();//获取 还没有发送的文字

//1.创建并启动任务调度器
var schedulerFactory = new StdSchedulerFactory();
var scheduler = await schedulerFactory.GetScheduler();
//2.创建作业
var sendMailJob = JobBuilder.Create<SendMailJob>().Build();
//3.创建触发器
var trigger = TriggerBuilder.Create()
   .WithCronSchedule("0 0/30 8-23 * * ?")//每天上午8点到晚上23点每隔30分钟运行
    .ForJob(sendMailJob)
    .Build();
//4.将创建好的作业和调度器添加至调度器
await scheduler.ScheduleJob(sendMailJob, trigger);
await scheduler.Start();

EventWaitHandle _waitHandle = new AutoResetEvent(false);
while (true)
{
    _waitHandle.WaitOne();
}